﻿Imports System.Xml
Imports System.IO
Imports System.IO.File

Public Class FrmEquipment

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        If Button5.Text = "修改" Then
            Robot_Company.ReadOnly = False
            Robot_Version.ReadOnly = False
            Robot_Datatime.Enabled = True
            Charge_Name.ReadOnly = False
            Charge_Telephone.ReadOnly = False
            Charge_Email.ReadOnly = False
            OPCVersion.ReadOnly = False
            SoftVersion.ReadOnly = False
            MachineID.ReadOnly = False
            LineID.ReadOnly = False
            StationID.ReadOnly = False
            Button5.Text = "保存"
        ElseIf Button5.Text = "保存" Then
            EquipmentInfo.Robot_Company = Robot_Company.Text
            EquipmentInfo.Robot_Version = Robot_Version.Text
            EquipmentInfo.Robot_Datatime = Robot_Datatime.Text
            EquipmentInfo.Charge_Name = Charge_Name.Text
            EquipmentInfo.Charge_Telephone = Charge_Telephone.Text
            EquipmentInfo.Charge_Email = Charge_Email.Text
            EquipmentInfo.OPCVersion = OPCVersion.Text
            EquipmentInfo.SoftVersion = SoftVersion.Text
            EquipmentInfo.MachineID = MachineID.Text
            EquipmentInfo.LineID = LineID.Text
            EquipmentInfo.StationID = StationID.Text
            Dim Machine As New XmlTextWriter(Application.StartupPath & "\EquipmentInfo.xml", System.Text.Encoding.GetEncoding("utf-8"))
            Try
                Machine.WriteStartDocument()
                Machine.Formatting = Formatting.Indented
                Machine.WriteStartElement("EquipmentInfo")
                Machine.WriteElementString("Robot_Company", Robot_Company.Text)
                Machine.WriteElementString("Robot_Version", Robot_Version.Text)
                Machine.WriteElementString("Robot_Datatime", Robot_Datatime.Text)
                Machine.WriteElementString("Charge_Name", Charge_Name.Text)
                Machine.WriteElementString("Charge_Telephone", Charge_Telephone.Text)
                Machine.WriteElementString("Charge_Email", Charge_Email.Text)
                Machine.WriteElementString("OPCVersion", OPCVersion.Text)
                Machine.WriteElementString("SoftVersion", SoftVersion.Text)
                Machine.WriteElementString("MachineID", MachineID.Text)
                Machine.WriteElementString("LineID", LineID.Text)
                Machine.WriteElementString("StationID", StationID.Text)
                Machine.WriteEndElement()
                Machine.Close()
                Robot_Company.ReadOnly = True
                Robot_Version.ReadOnly = True
                Robot_Datatime.Enabled = False
                Charge_Name.ReadOnly = True
                Charge_Telephone.ReadOnly = True
                Charge_Email.ReadOnly = True
                OPCVersion.ReadOnly = True
                SoftVersion.ReadOnly = True
                MachineID.ReadOnly = True
                LineID.ReadOnly = True
                StationID.ReadOnly = True
                'Dim data As String = EquipmentInfo.Robot_Company & "," & EquipmentInfo.Robot_Version & "," & EquipmentInfo.Robot_Datatime & "," & EquipmentInfo.Charge_Name & "," & EquipmentInfo.Charge_Telephone & "," & EquipmentInfo.Charge_Email & "," & EquipmentInfo.OPCVersion & "," & EquipmentInfo.SoftVersion & "," & EquipmentInfo.MachineID & "," & EquipmentInfo.LineID & "," & EquipmentInfo.StationID & ","
                'UploadMessage(data, "Equipment_message")
                FrmMain.OPC_RefreshData_Info()
                Button5.Text = "修改"
                MsgBox("设备信息保存成功！")
            Catch ex As Exception
                MsgBox("设备信息保存失败!" & ex.Message.ToString)
                Machine.Close()
            Finally

            End Try
        End If
    End Sub

    Private Sub 设备管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        FrmMain.loadequipment()
        Dim xmlpath = Application.StartupPath & "\EquipmentInfo.xml"
        If Exists(xmlpath) Then
            Robot_Company.Text = EquipmentInfo.Robot_Company
            Robot_Version.Text = EquipmentInfo.Robot_Version
            Robot_Datatime.Text = EquipmentInfo.Robot_Datatime
            Charge_Name.Text = EquipmentInfo.Charge_Name
            Charge_Telephone.Text = EquipmentInfo.Charge_Telephone
            Charge_Email.Text = EquipmentInfo.Charge_Email
            OPCVersion.Text = EquipmentInfo.OPCVersion
            SoftVersion.Text = EquipmentInfo.SoftVersion
            MachineID.Text = EquipmentInfo.MachineID
            LineID.Text = EquipmentInfo.LineID
            StationID.Text = EquipmentInfo.StationID
        End If
    End Sub
End Class